/* eslint-disable @typescript-eslint/no-var-requires */
const { spawn } = require('child_process');
const process = spawn('npm', ['run', 'test']);

const dataBegin = new Date();

process.stdout.on('data', (data) => {
    console.log(data.toString());
    if(data.toString().includes('created bundle.js')){
        const dataEnd = new Date();
        console.log(`Duration: ${dataEnd - dataBegin}ms`);
        process.kill();
    }
});

// 添加错误处理
process.stderr.on('data', (data) => {
    console.error(`Error: ${data}`);
});

process.on('close', (code) => {
    const dateEnd = new Date();
    console.log(`Duration: ${dateEnd - dataBegin}ms`);
    console.log(`子进程退出，退出码 ${code}`);
});